/*******************************************************************************
 * Copyright (c) 2011 Jovansonlee B. Cesar.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Jovansonlee B. Cesar - initial API and implementation
 ******************************************************************************/
package com.ivanceras.server.services;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ReadFilesServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6300333261757694586L;

	public void doGet(HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException {
		String filename = "/WEB-INF/web.xml";
		ServletContext context = getServletContext();

		InputStream inp = context.getResourceAsStream(filename);
		if (inp != null) {
			InputStreamReader isr = new InputStreamReader(inp);
			BufferedReader reader = new BufferedReader(isr);
			PrintWriter pw = res.getWriter();
			pw.println("<pre>");
			String text = "";

			while ((text = reader.readLine()) != null) {
				pw.println(text);
			}
			pw.println("</pre>");
		}		
	}
}
